
// class 
CSelectForm = function() {
};


CSelectForm.prototype = {
	_modes : {},
	// id_config_form
	initialize: function() {
		localConsole.debug.call(this, 'Slect from , init ', 'myObj: ');
		var allInputs = $(":input");
		var formChildren = $("form > *");
		$("#form_test").text("Found " + allInputs.length + " inputs and the form has " +
		                 formChildren.length + " children.");
		$("form").submit(function () { return false; });

		var outer = this;
		$('#id_config_form input[type="checkbox"]').click( function() { outer.getMode(outer) ; });
		this.getMode();

		// key 
		$("#id_setkey").click( this.setSessionKey);

		// start castle 
		$("select").change(this.setStartCastle);
		// this.setStartCastle();
	},

	getMode: function(outer) {
		if ( !outer )
			outer = this;
		outer._modes = {} ; // rest 
		$('#id_config_form input[type="checkbox"]:checked').each( function() { 
			outer._modes[$(this).val() ] = true;
		    });

		localConsole.debug.call(this, 'Slect getMode', '_modes: ' , outer._modes);
	},
	setSessionKey: function() {
		this.session_key = $("#id_session_key").val();
		$("#form_test").text( this.session_key );
	},
	getSessionKey: function() {
		return this.session_key;
		},
	setStartCastle: function() {
		this.startCastle = $("#id_start_castle").val();
		debug_log( " start c " + this.startCastle );
			},
};

// plugin clear form

$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};

// $('form').clearForm()
// $(':input').clearForm()